package gui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

//////////////////////////////////////////////////////////////////////////
//// ProgressDialog
/**
 
@author Ivan Jeukens
@version v 0.1 1/03/2002
*/
public class ProgressDialog extends JDialog {
    
    public ProgressDialog(Frame parent) {
        super(parent);
        setTitle("Analyzing");
        setSize(500, 300);

        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());

        _msgArea = new JTextArea(20, 100);
        _msgArea.setEditable(false);
        
        JScrollPane sp = new JScrollPane(_msgArea);
        panel.add(sp, BorderLayout.CENTER);
        
        _progressBar = new JProgressBar(0, 10);
        _progressBar.setValue(0);
        _progressBar.setStringPainted(true);
        panel.add(_progressBar, BorderLayout.NORTH);
        
        _doneButton = new JButton("done");
        _doneButton.setEnabled(false);
        _doneButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                hide();
	    }
        });

        panel.add(_doneButton, BorderLayout.SOUTH);
        
        getContentPane().add(panel);

        Toolkit tk = Toolkit.getDefaultToolkit();
        int w = tk.getScreenSize().width/3;
        int h = tk.getScreenSize().height/3;

        setLocation(w, h);
    }

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////
    
    public void reset() {
        _progressBar.setValue(_progressBar.getMinimum());
    }
    
    public void setMaximum(int value) {
        _progressBar.setMaximum(value);
    }    
    
    public void addMessage(String msg, int newLines) {
        String text = _msgArea.getText();
        
        StringBuffer buf = new StringBuffer();
        for(int i = 0;i < newLines;i++) buf.append("\n");
        buf.append(msg);

        _msgArea.setText(text + buf.toString());
    }

    public void done() {
        _doneButton.setEnabled(true);
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    ////


    ///////////////////////////////////////////////////////////////////
    ////                      private variables                    ////

    private JProgressBar _progressBar;
    private JTextArea _msgArea;
    private JButton _doneButton;
}
